package dbRedis

import (
	. "gitee.com/kingzyt/common/objPool"
)

var g_dbArgs = NewObjPool("g_dbArgs", 20, 5, func() interface{} {
	return &Args{list: []interface{}{}}
})

func NewArgs(argsLen int) *Args {
	args := g_dbArgs.Pull().(*Args)
	args.reset(argsLen)
	return args
}

type Args struct {
	list []interface{}
	idx  int
}

func (self *Args) NextIdx() int {
	self.idx++
	return self.idx
}
func (self *Args) Release() {
	for i := 0; i < len(self.list); i++ {
		self.list[i] = nil
	}
	g_dbArgs.Push(self)
}
func (self *Args) reset(argsLen int) {
	if argsLen <= 0 {
		return
	}

	listLen := cap(self.list)
	if len(self.list) < listLen {
		self.list = self.list[:listLen]
	}
	if argsLen < listLen {
		self.list = self.list[:argsLen]
	} else if argsLen == listLen {
		// do nothing
	} else {
		delta := argsLen - listLen
		for i := 0; i < delta; i++ {
			self.list = append(self.list, nil)
		}
	}
	self.idx = -1
}
func (self *Args) GetList() []interface{} {
	return self.list
}
